/**********************************************************************************************************\
 * Copyright (c) 2006, Dan Kruchinin (aka asgard).                                                        *
 * All rights reserved.                                                                                   *
 *                                                                                                        *
 * -> errors.h                                                                                            *
 * errors control system.                                                                                 *
 *                                                                                                        *
 * Redistribution and use of this software in source and binary forms, with or without modification, are  *
 * permitted provided that the following conditions are met:                                              *
 *                                                                                                        *
 * - Redistributions of source code must retain the above                                                 *
 * copyright notice, this list of conditions and the                                                      *
 * following disclaimer.                                                                                  *
 *                                                                                                        *
 * - Redistributions in binary form must reproduce the above                                              *
 * copyright notice, this list of conditions and the                                                      *
 * following disclaimer in the documentation and/or other                                                 *
 * materials provided with the distribution.                                                              *
 *                                                                                                        *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT     *
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    *
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                             *
\**********************************************************************************************************/

#ifndef DS_ERRORS_H
#define DS_ERRORS_H
#include <pthread.h>

/* if you wan to add your error code, just increment DSERR_MAX and */
#define DSERRS_MAX 6

/* add new defenition strting with DSERR_ */
#define DSERR_NOERRS        0
#define DSERR_SYSTEM       -12345
#define DSERR_NOERRS_MSG    "there are no any errors. all is ok ;)"

#define NDSERRS             6
#define DSERR_EMPTY_DS     -1
#define DSERR_EMPTY_NODE   -2
#define DSERR_NO_CMP_FUNC  -3
#define DSERR_DS_JDIFF     -4
#define DSERR_DUPLICATE    -5
#define DSERR_ERRPOSDR     -6

#define DS_ERRPOS_MAIN 0
#define ERRVN          4
/* this macro used to modify negative errcode getted from user or holded in errcode ds_errno field */
#define _err(code) (-(code) - 1)


typedef struct ds_errno {
  int errcode;
  char** errdescr;
  int errnum;
} ds_errno_t;

typedef struct ds_errs {
  ds_errno_t* errcodes;
  int n;
  int cur_pos;
  int inited;
} ds_errs_t;

#define DS_ERRNO_POSITION(name)				\
  static int (name) = -1;

int ds_errcode(void);
char* ds_strerror(const int);
char* ds_errmsg(void);
void _ds_set_errno(const int, const int);
int _ds_get_errno(const int);
int _ds_pos_is_reg(const int);
int _ds_reg_errno_pos(char**, const int);


#endif /* DS_ERRORS_H */
